﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinFu.IoC.Interfaces;
using LinFu.IoC;
using CoreEx.Services;

namespace CoreEx.Wcf.Common
{
    public static class TypeExtensions
    {
        private static readonly IServiceContainer _serviceContainer;
        private static readonly IServiceContractResolver _serviceContractResolver;
        //private static readonly IEnumerable<Type> _serviceContractTypes;
        private static readonly IEnumerable<Type> _dataContractTypes; 
        
        static TypeExtensions()
        {
            _serviceContainer = ServiceLocator.Container;
            _serviceContractResolver = _serviceContainer.GetService<IServiceContractResolver>();
            //_serviceContractTypes = _serviceContainer.GetService<IList<Type>>("ServiceContractTypes");
            //_dataContractTypes = _serviceContainer.GetService<IList<Type>>("DataContractTypes");
        }

        public static bool IsServiceContract(this Type type)
        {
            return _serviceContractResolver.IsServiceContract(type);            
        }

        public static bool IsDataContract(this Type type)
        {
            return _dataContractTypes.Contains(type);
        }
    }
}
